module(...,package.seeall)

function new()
    local transManager = require("transitionManager").new()

    local localGroup = display.newGroup()
    
    local cena1 = display.newImage("images/backgrounds/intro/cena_01.jpg")
    local cena2 = display.newImage("images/backgrounds/intro/cena_02.jpg")
    local cena3 = display.newImage("images/backgrounds/intro/cena_03.jpg")
    local cena4 = display.newImage("images/backgrounds/intro/cena_04.jpg")
    local cena5 = display.newImage("images/backgrounds/intro/cena_05.jpg")
    local cena6 = display.newImage("images/backgrounds/intro/cena_06.jpg")
    
    cena1.alpha = 0; cena2.alpha = 0; cena3.alpha = 0
    cena4.alpha = 0; cena5.alpha = 0; cena6.alpha = 0
    
    transManager:add( cena1, {delay=100, time=500, alpha = 1, onComplete = function ()
        transManager:add( cena1, {delay=4000, time=500, alpha = 0} )
        transManager:add (cena2, {delay=4000, time=500, alpha = 1, onComplete = function ()
            transManager:add( cena2, {delay=4000, time=500, alpha = 0} )
            transManager:add (cena3, {delay=4000, time=500, alpha = 1, onComplete = function ()
                transManager:add( cena3, {delay=4000, time=500, alpha = 0} )
                transManager:add (cena4, {delay=4000, time=500, alpha = 1, onComplete = function ()
                    transManager:add( cena4, {delay=4000, time=500, alpha = 0} )
                    transManager:add (cena5, {delay=4000, time=500, alpha = 1, onComplete = function ()
                        transManager:add( cena5, {delay=4000, time=500, alpha = 0} )
                        transManager:add (cena6, {delay=4000, time=500, alpha = 1, onComplete = function ()
                            timer.performWithDelay(3000, function(e) director:changeScene(_G.currentMode, "crossfade"); timer.cancel(e.source) end, 0)
                        end
                        })
                    end
                    })
                end
                })
            end
            })
        end
        })
    end
    } )
    
    localGroup:insert(cena6)
    localGroup:insert(cena5)
    localGroup:insert(cena4)
    localGroup:insert(cena3)
    localGroup:insert(cena2)
    localGroup:insert(cena1)
    
    local function touchEvent(e)
        if (e.phase == "ended") then
            transManager:cancelAll()
            director:changeScene(_G.currentMode, "crossfade")
        end
    end
    
    localGroup:addEventListener("touch", touchEvent)
    
    return localGroup
end